package com.qf.controller;

import com.qf.entity.Book;
import com.qf.service.BookService;
import com.qf.service.impl.BookServiceImpl;
import com.qf.utils.Page;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/*
杨威
2021/9/13
22:48
*/
@WebServlet("/ShowAllBookController")
public class ShowAllBookController extends HttpServlet {
    BookService bookService=new BookServiceImpl();
    private static Page page;
    static {
        page=new Page();
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pageIndex = request.getParameter("pageIndex");

        if(pageIndex==null){
            pageIndex="1";
        }
        //如果page不为空，修改pageIndex属性
        if(page!=null){
            page.setPageIndex(Integer.valueOf(pageIndex));
        }
        List<Book> books = bookService.showAllBookByPage(page);
        request.setAttribute("books",books);
        request.setAttribute("page",page);
        request.getRequestDispatcher("/showAllBook.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
